﻿Option Explicit On

Imports System.Data
Imports System.Data.SqlClient



Public Class DataBinding

    'Public Overloads Shared Sub BindListView(ByVal Data As DataTable, ByRef ListViewControl As ListView, Optional ByVal StripCRLF As Boolean = False)
    '    ' populate and databind listview control with data in supplied datatable

    '    Dim lvi As ListViewItem
    '    Dim subi As ListViewItem.ListViewSubItem
    '    Dim i As Integer
    '    Dim myRow As DataRow

    '    Try

    '        ListViewControl.Items.Clear()


    '        For Each myRow In Data.Rows

    '            lvi = New ListViewItem

    '            If Not IsDBNull(myRow.Item(0)) Then
    '                lvi.Text = myRow.Item(0)
    '            End If

    '            For i = 1 To myRow.Table.Columns.Count - 1

    '                subi = New ListViewItem.ListViewSubItem

    '                If Not IsDBNull(myRow.Item(i)) Then
    '                    If Not StripCRLF Then
    '                        subi.Text = myRow.Item(i)
    '                    Else
    '                        Dim s As String = myRow.Item(i)

    '                        s = s.Replace(Chr(13), "").Replace(Chr(10), "")
    '                        subi.Text = s

    '                    End If
    '                End If

    '                lvi.SubItems.Add(subi)

    '            Next

    '            ListViewControl.Items.Add(lvi)

    '        Next

    '        Data.Dispose()

    '    Catch ex As Exception
    '        MsgBox(ex.Message, MsgBoxStyle.Critical)
    '    End Try


    'End Sub

    'Public Overloads Shared Sub BindListView(ByVal SQL As String, ByRef ListViewControl As ListView, Optional ByVal StripCRLF As Boolean = False)
    '    ' populate and databind listview control with data returned by SQL string

    '    Dim SQLReader As SqlDataReader = DB.GetSQLDataReader(SQL)
    '    Dim lvi As ListViewItem
    '    Dim subi As ListViewItem.ListViewSubItem
    '    Dim i As Integer

    '    Try

    '        ListViewControl.Items.Clear()

    '        Do
    '            While SQLReader.Read

    '                lvi = New ListViewItem

    '                If Not IsDBNull(SQLReader.Item(0)) Then
    '                    lvi.Text = SQLReader.Item(0)
    '                End If

    '                For i = 1 To SQLReader.FieldCount - 1

    '                    subi = New ListViewItem.ListViewSubItem

    '                    If Not IsDBNull(SQLReader.Item(i)) Then
    '                        If Not StripCRLF Then
    '                            subi.Text = SQLReader.Item(i)
    '                        Else
    '                            Dim s As String = SQLReader.Item(i)

    '                            s = s.Replace(Chr(13), "").Replace(Chr(10), "")
    '                            subi.Text = s

    '                        End If
    '                    End If

    '                    lvi.SubItems.Add(subi)

    '                Next

    '                ListViewControl.Items.Add(lvi)

    '            End While

    '        Loop While SQLReader.NextResult

    '        SQLReader.Close()
    '        'DB.CloseDB()

    '    Catch ex As Exception
    '        MsgBox(ex.Message, MsgBoxStyle.Critical)
    '    End Try


    'End Sub

    'Public Shared Sub SelectListviewRow(ByVal AnyList As ListView, ByVal ListId As Long)

    '    Dim li As ListViewItem

    '    AnyList.SelectedItems.Clear()

    '    For Each li In AnyList.Items
    '        If li.SubItems(0).Text = ListId Then
    '            li.Selected = True
    '            Exit For
    '        End If
    '    Next

    '    AnyList.Update()

    'End Sub

    'Public Class MyListItem
    '    Public ItemText As String
    '    Public ItemValue As Long
    'End Class

End Class
